home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_lib1 / rkrm_lib1.lha / Intuition / Intuition_GUI / easyintuition37.c < prev   
C/C++ Source or Header  |  1992-09-03  |  7KB  |  188 lines

  1. ;/*
  2. lc -L -j73 easyintuition37.c
  3. quit
  4. */
  5.  
  6. /*
  7. Copyright (c) 1992 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga, Inc. for
  10. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  11. published by Addison-Wesley (ISBN 0-201-56774-1).
  12.  
  13. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  14. information on the correct usage of the techniques and operating system
  15. functions presented in these examples.  The source and executable code
  16. of these examples may only be distributed in free electronic form, via
  17. bulletin board or as part of a fully non-commercial and freely
  18. redistributable diskette.  Both the source and executable code (including
  19. comments) must be included, without modification, in any copy.  This
  20. example may not be published in printed form or distributed with any
  21. commercial product.  However, the programming techniques and support
  22. routines set forth in these examples may be used in the development
  23. of original executable software products for Commodore Amiga computers.
  24.  
  25. All other rights reserved.
  26.  
  27. This example is provided "as-is" and is subject to change; no
  28. warranties are made.  All use is at your own risk. No liability or
  29. responsibility is assumed.
  30. */
  31.  
  32. /* easyintuition37.c -- Simple Intuition program for V37
  33. /* (Release 2) and later versions of the operating system. */
  34. /* Compiled with Lattice C v5.04: lc -L easyintuition37.c  */
  35.  
  36. #include <exec/types.h>             /* The Amiga data types file.         */
  37. #include <intuition/intuition.h>    /* Intuition data strucutres, etc.    */
  38. #include <graphics/displayinfo.h>   /* Release 2 Amiga display mode ID's  */
  39. #include <libraries/dos.h>          /* Official return codes defined here */
  40.  
  41. #include <clib/exec_protos.h>       /* Exec function prototypes           */
  42. #include <clib/intuition_protos.h>  /* Intuition function prototypes      */
  43.  
  44. /* Force use of new variable names to help prevent errors  */
  45. #define INTUI_V36_NAMES_ONLY
  46.  
  47. #ifdef LATTICE                      /* Disable Ctrl-C handling in SAS/C   */
  48. int CXBRK(void)  {return(0);}
  49. void chkabort(void) {return;}
  50. #endif
  51.  
  52. /* Use lowest non-obsolete version that supplies the functions needed. */
  53. #define INTUITION_REV 37
  54.  
  55. /* Declare the prototypes of our own functions.  Prototypes for system */
  56. /* functions are declared in the header files in the clib directory.   */
  57. VOID cleanExit( struct Screen *, struct Window *, LONG );
  58. BOOL handleIDCMP( struct Window *);
  59.  
  60. struct Library *IntuitionBase = NULL;
  61.  
  62. /* Position and sizes for our window */
  63. #define WIN_LEFTEDGE   20
  64. #define WIN_TOPEDGE    20
  65. #define WIN_WIDTH     400
  66. #define WIN_MINWIDTH   80
  67. #define WIN_HEIGHT    150
  68. #define WIN_MINHEIGHT  20
  69.  
  70.  
  71. VOID main(int argc, char *argv[])
  72. {
  73.     /* Declare variables here */
  74.     ULONG signalmask, winsignal, signals;
  75.     BOOL done = FALSE;
  76.     UWORD pens[]={~0};
  77.  
  78.     struct Screen *screen1 = NULL;
  79.     struct Window *window1 = NULL;
  80.  
  81.     /* Open the Intuition Library */
  82.     IntuitionBase = OpenLibrary( "intuition.library",INTUITION_REV );
  83.     if (IntuitionBase == NULL)
  84.         cleanExit(screen1, window1, RETURN_WARN);
  85.  
  86.     /* Open any other required libraries and make */
  87.     /* any assignments that were postponed above  */
  88.  
  89.     /* Open the screen */
  90.     screen1 = OpenScreenTags(NULL,
  91.                              SA_Pens,  (ULONG)pens,
  92.                              SA_DisplayID, HIRES_KEY,
  93.                              SA_Depth, 2,
  94.                              SA_Title, (ULONG)"Our Screen",
  95.                              TAG_DONE);
  96.  
  97.     if (screen1 == NULL)
  98.         cleanExit(screen1, window1, RETURN_WARN);
  99.  
  100.     /* ... and open the window */
  101.     window1 = OpenWindowTags(NULL,
  102.                              /* Specify window dimensions and limits */
  103.                              WA_Left,         WIN_LEFTEDGE,
  104.                              WA_Top,          WIN_TOPEDGE,
  105.                              WA_Width,        WIN_WIDTH,
  106.                              WA_Height,       WIN_HEIGHT,
  107.                              WA_MinWidth,     WIN_MINWIDTH,
  108.                              WA_MinHeight,    WIN_MINHEIGHT,
  109.                              WA_MaxWidth,     ~0,
  110.                              WA_MaxHeight,    ~0,
  111.                              /* Specify the system gadgets we want */
  112.                              WA_CloseGadget,  TRUE,
  113.                              WA_SizeGadget,   TRUE,
  114.                              WA_DepthGadget,  TRUE,
  115.                              WA_DragBar,      TRUE,
  116.                              /* Specify other attributes           */
  117.                              WA_Activate,     TRUE,
  118.                              WA_NoCareRefresh,TRUE,
  119.  
  120.                              /* Specify the events we want to know about */
  121.                              WA_IDCMP,        IDCMP_CLOSEWINDOW,
  122.  
  123.                              /* Attach the window to the open screen ...*/
  124.                              WA_CustomScreen, screen1,
  125.                              WA_Title,        "EasyWindow",
  126.                              WA_ScreenTitle,  "Our Screen - EasyWindow is Active",
  127.                              TAG_DONE);
  128.     if (window1 == NULL)
  129.         cleanExit(screen1, window1, RETURN_WARN);
  130.  
  131.     /* Set up the signals for the events we want to hear about ...   */
  132.     winsignal = 1L << window1->UserPort->mp_SigBit;  /* window IDCMP */
  133.     signalmask = winsignal;   /* we are only waiting on IDCMP events */
  134.  
  135.     /* Here's the main input event loop where we wait for events.    */
  136.     /* We have asked Intuition to send us CLOSEWINDOW IDCMP events   */
  137.     /* Exec will wake us if any event we are waiting for occurs.     */
  138.     while( !done )
  139.     {
  140.         signals = Wait(signalmask);
  141.  
  142.         /* An event occurred - now act on the signal(s) we received.*/
  143.         /* We were only waiting on one signal (winsignal) in our    */
  144.         /* signalmask, so we actually know we received winsignal.   */
  145.         if(signals & winsignal)
  146.             done = handleIDCMP(window1);    /* done if close gadget */
  147.     }
  148.     cleanExit(screen1, window1, RETURN_OK); /* Exit the program     */
  149. }
  150.  
  151. BOOL handleIDCMP( struct Window *win )
  152. {
  153.     BOOL done = FALSE;
  154.     struct IntuiMessage *message = NULL;
  155.     ULONG class;
  156.  
  157.     /* Examine pending messages */
  158.     while( message = (struct IntuiMessage *)GetMsg(win->UserPort) )
  159.     {
  160.         class = message->Class;  /* get all data we need from message */
  161.  
  162.         /* When we're through with a message, reply */
  163.         ReplyMsg( (struct Message *)message);
  164.  
  165.         /* See what events occurred */
  166.         switch( class )
  167.         {
  168.             case IDCMP_CLOSEWINDOW:
  169.                 done = TRUE;
  170.                 break;
  171.             default:
  172.                 break;
  173.         }
  174.     }
  175.     return(done);
  176. }
  177.  
  178. VOID cleanExit( struct Screen *scrn, struct Window *wind, LONG returnValue )
  179. {
  180.     /* Close things in the reverse order of opening */
  181.     if (wind) CloseWindow( wind );      /* Close window if opened */
  182.     if (scrn) CloseScreen( scrn );      /* Close screen if opened */
  183.  
  184.     /* Close the library, and then exit */
  185.     if (IntuitionBase) CloseLibrary( IntuitionBase );
  186.     exit(returnValue);
  187. }
  188.